package com.jic.market.controller.manage;

import com.alibaba.fastjson.JSON;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.market.api.manage.SkillManageApi;
import com.jic.market.request.CouponDetailRequest;
import com.jic.market.request.manager.base.MerchantDeleteRequest;
import com.jic.market.request.manager.base.PromotionIdRequest;
import com.jic.market.request.manager.base.StoreDeleteRequest;
import com.jic.market.request.manager.coupon.CouponTemplatRequest;
import com.jic.market.request.manager.skill.*;
import com.jic.market.response.manager.skill.*;
import com.jic.market.service.allocation.AllocationLogicService;
import com.jic.market.service.base.BaseActivityService;
import com.jic.market.service.skill.SkillActivityConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: gaolanyu
 * @date: 2020-03-12
 * @remark:
 */
@RestController
@RequestMapping("/skill")
@Api(tags = {"秒杀后台管理系统"})
@Slf4j
public class SkillManageController implements SkillManageApi {
    @Autowired
    SkillActivityConfigService skillActivityConfigService;
    @Autowired
    BaseActivityService baseActivityService;
    @Autowired
    AllocationLogicService allocationLogicService;

    @Override
    @ApiOperation(value = "增加秒杀基础配置")
    public RestResult<String> addSkillConfig(SkillConfigAddRequest skillConfigAddRequest) {
        return skillActivityConfigService.addSkillConfig(skillConfigAddRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀基础配置")
    public RestResult<SkillConfigQueryResponse> querySkillConfig(PromotionIdRequest promotionIdRequest) {
        return skillActivityConfigService.querySkillConfig(promotionIdRequest);
    }

    @Override
    @ApiOperation(value = "批量查询秒杀基础配置")
    public RestResult<List<SkillConfigQueryResponse>> querySkillConfigList(SkillBatchQueryRequest skillBatchQueryRequest) {
        return skillActivityConfigService.querySkillConfigList(skillBatchQueryRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀基础配置分页")
    public RestResult<PageResult<SkillConfigQueryResponse>> querySkillConfigPage(SkillConfigQueryPageRequest skillConfigQueryPageRequest) {
        log.info("分页查询秒杀活动，入参{}", JSON.toJSONString(skillConfigQueryPageRequest));
        RestResult<PageResult<SkillConfigQueryResponse>> response = skillActivityConfigService.querySkillConfigPage(skillConfigQueryPageRequest);
        log.info("分页查询秒杀活动，出参{}", JSON.toJSONString(response));
        return response;
    }

    @Override
    @ApiOperation(value = "更新秒杀基础配置")
    public RestResult<Boolean> updateSkillConfig(SkillConfigUpdateaRequest skillConfigUpdateaRequest) {
        return skillActivityConfigService.updateSkillConfig(skillConfigUpdateaRequest);
    }

    @ApiOperation(value = "复制秒杀配置")
    @Override
    public RestResult<String> copySkillConfig(PromotionIdRequest promotionIdRequest) {
        return skillActivityConfigService.copySkillConfig(promotionIdRequest,false);
    }

    @ApiOperation(value = "关闭秒杀")
    @Override
    public RestResult<Boolean> colseSkillConfig(PromotionIdRequest promotionIdRequest) {
        return skillActivityConfigService.colseSkillConfig(promotionIdRequest);
    }

    @ApiOperation(value = "删除秒杀配置")
    @Override
    public RestResult<Boolean> deleteSkillConfig(PromotionIdRequest promotionIdRequest) {
        return skillActivityConfigService.deleteSkillConfig(promotionIdRequest);
    }

    @Override
    @ApiOperation(value = "增加秒杀商家配置")
    public RestResult<Boolean> addSkillMerchantConfig(SkillMerchantAddRequest skillMerchantAddRequest) {
        return skillActivityConfigService.addSkillMerchantConfig(skillMerchantAddRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀商家配置")
    public RestResult<SkillMerchantResponse> querySkillMerchant(CouponDetailRequest promotionIdRequest) {
        return skillActivityConfigService.querySkillMerchant(promotionIdRequest);
    }

    @Override
    @ApiOperation(value = "删除秒杀商家配置")
    public RestResult<Boolean> deleteSkillMerchant(MerchantDeleteRequest merchantDeleteRequest) {
        return skillActivityConfigService.deleteSkillMerchant(merchantDeleteRequest);
    }

    @Override
    @ApiOperation(value = "增加秒杀店铺配置")
    public RestResult<Boolean> addSkillStoreConfig(SkillStoreAddRequest skillStoreAddRequest) {
        return skillActivityConfigService.addSkillStoreConfig(skillStoreAddRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀店铺配置")
    public RestResult<SkillStoreResponse> querySkillStore(CouponDetailRequest promotionIdRequest) {
        return skillActivityConfigService.querySkillStore(promotionIdRequest);
    }

    @Override
    @ApiOperation(value = "删除秒杀店铺配置")
    public RestResult<Boolean> deleteSkillStore(StoreDeleteRequest storeDeleteRequest) {
        return skillActivityConfigService.deleteSkillStore(storeDeleteRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀时间间隔配置")
    public RestResult<SkillTimeQueryResponse> queryTimeOfDate(PromotionIdRequest promotionIdRequest) {
        return skillActivityConfigService.queryTimeOfDate(promotionIdRequest);
    }

    @Override
    @ApiOperation(value = "删除秒杀时间间隔配置")
    public RestResult<Boolean> deleteTimeOfDate(SkillDeleteTimeOfDateRequest skillDeleteTimeOfDateRequest) {
        return skillActivityConfigService.deleteTimeOfDate(skillDeleteTimeOfDateRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀店铺配置")
    public RestResult<SkillStoreQueryResponse> queryStoreInfo(PromotionIdRequest promotionIdRequest) {
        return skillActivityConfigService.queryStoreInfo(promotionIdRequest);
    }

    @Override
    @ApiOperation(value = "增加秒杀商品配置")
    public RestResult<Boolean> addGoodsConfig(SkillGoodsIdsRequest skillGoodsRequest) {
        return skillActivityConfigService.addGoodsConfig(skillGoodsRequest);
    }

    @Override
    public RestResult<Boolean> addAllGoodsConfig(SkillGoodsIdsRequest skillGoodsRequest) {
        return skillActivityConfigService.addAllGoodsConfig(skillGoodsRequest);
    }

    @Override
    @ApiOperation(value = "更新秒杀商品配置")
    public RestResult<Boolean> updateGoodsConfig(SkillGoodsRequest skillGoodsRequest) {
        return skillActivityConfigService.updateGoodsConfig(skillGoodsRequest);
    }

    @Override
    @ApiOperation(value = "删除秒杀商品配置")
    public RestResult<Boolean> deleteGoods(SkillGoodsDeleteRequest skillGoodsDeleteRequest) {
        return skillActivityConfigService.deleteGoods(skillGoodsDeleteRequest);
    }

    @Override
    @ApiOperation(value = "批量删除秒杀商品配置")
    public RestResult<Boolean> deleteBatchGoods(SkillBatchDeleteRequest skillBatchDeleteRequest) {
        return skillActivityConfigService.deleteBatchGoods(skillBatchDeleteRequest);
    }

    @Override
    @ApiOperation(value = "查询秒杀商品配置")
    public RestResult<SkillGoodsQueryResponse> queryGoodsId(SkillDeleteTimeOfDateRequest skillDeleteTimeOfDateRequest) {
        return skillActivityConfigService.queryGoodsId(skillDeleteTimeOfDateRequest);
    }

    @Override
    @ApiOperation(value = "审核")
    public RestResult<Boolean> checkCoupon(SkillCheckRequest skillCheckRequest) {
        RestResult<Boolean> restResult= skillActivityConfigService.checkCoupon(skillCheckRequest);
        return restResult;
    }

    @Override
    @ApiOperation(value = "更新活动图片")
    public RestResult<Boolean> updateImagesUrl(SkillImagesUrlUpdateRequest skillImagesUrlUpdateRequest) {
        return skillActivityConfigService.updateImagesUrl(skillImagesUrlUpdateRequest);
    }

    @Override
    public RestResult<String> saveTemplate(CouponTemplatRequest couponTemplatRequest) {
        return skillActivityConfigService.saveTemplate(couponTemplatRequest);
    }
}
